package com.leyu.mall.common.filter;

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.leyu.mall.domain.cms.CmsShopConfig;
public class LoginFilter implements Filter
{
	private static Log		log	= LogFactory.getLog(LoginFilter.class);
	private ServletContext	sc;

	public LoginFilter()
	{
	}

	public void doFilter(ServletRequest srequest, ServletResponse sresponse, FilterChain chain) throws IOException, ServletException
	{
//		CmsShopConfig shopconfig= cmsShopConfigService.getCmsShopConfig(1L);
		
		
		HttpServletRequest request = (HttpServletRequest) srequest;
		HttpServletResponse response = (HttpServletResponse) sresponse;
		HttpSession session = request.getSession(true);
		Object loginInfoObj = session.getAttribute("loginSessionUser");
		if (loginInfoObj == null)
		{
			log.error("login error...");
			response.sendRedirect("http://localhost:8080/econe/login");
		} else
		{
			log.debug("login..." + loginInfoObj);
		}
		chain.doFilter(request, response);
	}

	public void init(FilterConfig config) throws ServletException
	{
		sc = config.getServletContext();
	}

	public void destroy()
	{
	}
}
